#!/usr/bin/env python3

# Copyright (c) 2020-2021 Fpemud <fpemud@sina.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


import os
import glob


class UserData:

    def __init__(self, prefix="/", user=None, read_only=False):
        self._prefix = prefix
        self._cfgDir = os.path.join(self._prefix, "home", user, ".config", "chromium")
        self._readOnly = read_only

    @property
    def paths(self):
        ret = [
            self._cfgDir,
            os.path.join(self._cfgDir, "Default"),
            os.path.join(self._cfgDir, "Local State"),
        ]

        # append all profile directories
        for fullfn in glob.glob(os.path.join(self._cfgDir, "*")):
            if fullfn not in ret and os.path.isdir(fullfn):
                ret.append(fullfn)

        return ret

    def get_profiles(self):
        # FIXME: read "Local State", return [profile-name]
        assert False

    def get_default_profile(self):
        # FIXME: return profile-name
        assert False

    def set_default_profile(self, profile_name):
        # FIXME
        assert False

    def get_start_with_last_profile(self):
        assert False

    def set_start_with_last_profile(self, value):
        assert False

    def load_profile(self, profile_name):
        # FIXME: return profile object
        assert False

    def create_profile(self, new_profile_name):
        # FIXME: no return
        assert False

    def clone_profile(self, profile_name, new_profile_name):
        # FIXME: no return
        assert False

    def rename_profile(self, profile_name, new_profile_name):
        # FIXME: no return
        assert False

    def delete_profile(self, profile_name):
        # FIXME: no return
        assert False
